import axios from 'axios'
import Qs from 'qs'

const Base = {
    API:'/fileImportApp',
    submit:function (_source,access_token,parameter,successCallBack,failCallBack) {
        let baseURL = this.API
        let formData = parameter.formData || {};
        let submitData = {}
        Object.keys(formData).forEach(item => {
            submitData["dto['"+item+"']"] = formData[item]
        })
        submitData["dto['access_token']"] = access_token;
        let submitParameter = {
            method: 'POST',
            responseType: 'json', // 默认的
            withCredentials: true, // 默认的
            baseURL: baseURL,
            url:'/fileImport/fileImportController!getFileImport.do',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
            },
            data:Qs.stringify(submitData),
            ...parameter
        }
        axios(submitParameter)
            .then((response) => {
                if(successCallBack)successCallBack(response.data)
            }).catch((error) => {
                if(failCallBack)failCallBack(error)
        })
    }
}

export default {
    install:function (Vue) {
        Vue.prototype.Base = Base
    }
}